Code:
#include "tipus.h"
int main(void)
{
int i = 0;
int nCorrecte = 0;
int nJugadors = 0;
char cMode;
int nDaus[4];
int error;
int nRes = 0, nOk = 0;
stPlayer jugador[4];
stCasella casella[97];
stDaus astDaus[4];
stPlayer jRanking[5];
srand(time(NULL));
//Inicialització llibreria allegro
allegro_init();
//Inicialització teclat
install_keyboard();
//Inicialització entorn grafic, finestra 800*600
error=set_gfx_mode(GFX_SAFE, 800, 600, 0, 0);
if (error==0){ //Entrar codi aquí!
while(nCorrecte == 0){
printf("Mode de joc <E o F>: ");
fflush(stdout);
nRes = scanf("%c",&cMode);
cMode = (char) tolower(cMode);
if(nRes == 1 && ( cMode == 'e' || cMode == 'f')){
nCorrecte = 1;
}
else{
printf("Error! Mode de joc incorrecte!\n");
}
getchar();
}
nCorrecte = 0;
while(nCorrecte == 0){
printf("\nNombre de jugadors: ");
fflush(stdout);
nRes = scanf("%d",&nJugadors);
if(nRes == 1 && (nJugadors >= 2 && nJugadors <= 4) ){
nCorrecte = 1;
}
else{
printf("Error, el nombre de jugadors ha d'estar entre 2 i 4.\n");
}
getchar();
}
for( i = 0; i < nJugadors; i++){
printf("\nNom Jugador %d: ", i+1);
if(fgets(jugador[i].strNom, sizeof(jugador[i].strNom),stdin) != NULL)
{
nRes = strlen(jugador[i].strNom);
if(nRes > 0 && jugador[i].strNom[nRes-1] == '\n')
jugador[i].strNom[nRes-1] = '\0';
jugador[i].nColorfitxa = 2 + i;
jugador[i].nCasella = 0;
}
}
printf("Daus de sortida: \n");
for(i = 0; i < nJugadors; i++){
astDaus[i].nDaus = rand() % 6+1;
astDaus[i].nOrdre = i;
printf("%d.%s - %d de 6\n",i+1,jugador[i].strNom,astDaus[i].nDaus);
}
ordenacio(jugador, astDaus, nJugadors);
printf(" Enter to continue o ESC to exit...\n");
do{
if (keypressed()) {
//ENTER...
if (key[KEY_ENTER]) {
llegeix(jRanking);
tauler(cMode,jugador, nJugadors,casella);
joc(jugador, nJugadors, casella, jRanking);
nOk = 1;
}
//ESC..
if (key[KEY_ESC]) {
printf("FINS AVIAT!\n");
nOk = 1;
exit(1);
}
//like fflush() in allegro.
clear_keybuf();
}
}while(!nOk);
llegeix(jRanking);
tauler(cMode,jugador, nJugadors,casella);
for(i = 0; i < nJugadors; i++){
circlefill(screen, 610, 150 + (20*i),6, jugador[i].nColorfitxa);
circle(screen, 610, 150 + (20*i),6, jugador[i].nColorfitxa);
textprintf_ex(screen, font, 645, 150 + (20*i), 0, 14, "%s", jugador[i].strNom);
}
joc(jugador, nJugadors, casella, jRanking);
}
else{
allegro_message("No es pot crear la finestra\n%s\n",allegro_error);
printf("No es pot crear la finestra\n%s\n",allegro_error);
}
//Close allegro
system("pause");
allegro_exit();
}
END_OF_MAIN();
The header "tipus.h" includes "allegro.h".